import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由全局前置导航
router.beforeEach((to, from, next) => {
  // TODO 验证token信息是否过期
  const token = window.localStorage.getItem('__token__')
  if (token) {
    next()
  } else {
    // 回到登录页面
    next({ name: 'login', })
  }
})

export default router
